package com.jftone.bh.app.service;

import com.jftone.bh.app.model.NtbUser;
import org.apache.log4j.Logger;
import org.jftone.annotation.Autowired;
import org.jftone.annotation.Service;
import org.jftone.dao.Dao;
import org.jftone.util.*;

import java.util.List;


@Service
public class VipTradeService {
	
	private Logger logger = Logger.getLogger(VipTradeService.class);
	
	@Autowired
	private Dao dao;

	public List<IData<String, Object>> queryList(IData<String, Object> data, Page page) throws Exception {
		List<IData<String, Object>> list = null;
		String userId = data.getString("userId", "");
		String tradeNo = data.getString("tradeNo", "");
		String status = data.getString("status", "");
		String sTime = data.getString("sTime", "");
		String eTime = data.getString("eTime", "");
		IData<String, Object> param = new DataMap<String, Object>();
		if(!StringUtil.isBlank(userId)){
			param.put("USER_ID", userId);
		}
		if(!StringUtil.isBlank(tradeNo)){
			param.put("TRADE_NO", tradeNo);
		}
		if(!StringUtil.isBlank(status)){
			param.put("STATUS", status);
		}
		if(!StringUtil.isBlank(sTime)){
			param.put("S_TIME", DateUtil.getMillisecond(DateUtil.parseDate(sTime)));
		}
		if(!StringUtil.isBlank(eTime)){
			param.put("E_TIME", DateUtil.getMillisecond(DateUtil.parseDate(eTime)));
		}
		list = dao.query("queryVipTradeList", param, page);
		param.clear();
		NtbUser ntbUser;
		for (IData<String, Object> point:list) {
			param.put("id",point.getInt("USER_ID"));
			ntbUser = dao.get(NtbUser.class,param);
			if(ntbUser != null){
				point.put("ACCOUNT", ntbUser.getAccount());
				point.put("USER_NAME", ntbUser.getUserName());
			}
		}
		return list;
	}

}
